package LinkedListPackage;

/**
 * @author Lzm
 * @version 1.0
 */
public class removeNthFromEnd_ {


  public ListNode removeNthFromEnd(ListNode head, int n) {
      if (head == null || n < 1 || n > 30){
        return null;
      }
      ListNode dummyHead = new ListNode();
      dummyHead.next = head;
      ListNode fast = dummyHead;
      ListNode slow = dummyHead;
      for (int i = 0 ; i < n ; i++){
        fast = fast.next;
      }
      while (fast.next != null){
        fast = fast.next;
        slow = slow.next;
      }
      slow.next = slow.next.next;
      return dummyHead.next;
  }
}
